package se.sweco.gpsservice.datatypes;

public class GPSDataGPGGA {
	String time = "";
	float Latitude = 0.0f;
	String LatitudeType = "";
	float Longitude = 0.0f;
	String LongitudeType = "";
	int Quality = 0;
	int numberOfSattelites = 0;
	float HorizontalDilution = 0.0f;
	float AntennaAltitude = 0.0f;
	String AntennaUnits = "";
	float GeoidalSeparation = 0.0f;
	String GeoidalUnits = "";
	String LastUpdate = "";
	String StationID = "";
	String CheckSum = "";
	
	public void parseData(String data) {
		String[] gpsData = data.split(",");
		String gpsDataType = gpsData[0].substring(1);
		
		if(gpsDataType.equals("GPGGA")) {
			if(!gpsData[1].trim().equals(""))
				time = gpsData[1];
			if(!gpsData[2].trim().equals(""))
				Latitude = new Float(gpsData[2]).floatValue();
			if(!gpsData[3].trim().equals(""))
				LatitudeType = gpsData[3];
			if(!gpsData[4].trim().equals(""))
				Longitude = new Float(gpsData[4]).floatValue();
			if(!gpsData[5].trim().equals(""))
				LongitudeType = gpsData[5];
			if(!gpsData[6].trim().equals(""))
				Quality = new Integer(gpsData[6]).intValue();
			if(!gpsData[7].trim().equals(""))
				numberOfSattelites = new Integer(gpsData[7]).intValue();
			if(!gpsData[8].trim().equals(""))
				HorizontalDilution = new Float(gpsData[8]).floatValue();
			if(!gpsData[9].trim().equals(""))
				AntennaAltitude = new Float(gpsData[9]).floatValue();
			if(!gpsData[10].trim().equals(""))
				AntennaUnits = gpsData[10];
			if(!gpsData[11].trim().equals(""))
				GeoidalSeparation = new Float(gpsData[11]).floatValue();
			if(!gpsData[12].trim().equals(""))
				GeoidalUnits = gpsData[12];
			if(!gpsData[13].trim().equals(""))
				LastUpdate = gpsData[13];
			
			StationID = gpsData[14].substring(0, gpsData[14].indexOf("*"));
			CheckSum = gpsData[14].substring(gpsData[14].indexOf("*"));
		}
	}
	
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public float getLatitude() {
		return Latitude;
	}
	public void setLatitude(float latitude) {
		Latitude = latitude;
	}
	public float getLongitude() {
		return Longitude;
	}
	public void setLongitude(float longitude) {
		Longitude = longitude;
	}
	public int getQuality() {
		return Quality;
	}
	public void setQuality(int quality) {
		Quality = quality;
	}
	public int getNumberOfSattelites() {
		return numberOfSattelites;
	}
	public void setNumberOfSattelites(int numberOfSattelites) {
		this.numberOfSattelites = numberOfSattelites;
	}
	public float getHorizontalDilution() {
		return HorizontalDilution;
	}
	public void setHorizontalDilution(float horizontalDilution) {
		HorizontalDilution = horizontalDilution;
	}
	public float getAntennaAltitude() {
		return AntennaAltitude;
	}
	public void setAntennaAltitude(float antennaAltitude) {
		AntennaAltitude = antennaAltitude;
	}
	public String getAntennaUnits() {
		return AntennaUnits;
	}
	public void setAntennaUnits(String antennaUnits) {
		AntennaUnits = antennaUnits;
	}
	public float getGeoidalSeparation() {
		return GeoidalSeparation;
	}
	public void setGeoidalSeparation(float geoidalSeparation) {
		GeoidalSeparation = geoidalSeparation;
	}
	public String getGeoidalUnits() {
		return GeoidalUnits;
	}
	public void setGeoidalUnits(String geoidalUnits) {
		GeoidalUnits = geoidalUnits;
	}
	public String getLastUpdate() {
		return LastUpdate;
	}
	public void setLastUpdate(String lastUpdate) {
		LastUpdate = lastUpdate;
	}
	public String getStationID() {
		return StationID;
	}
	public void setStationID(String stationID) {
		StationID = stationID;
	}
	public String getCheckSum() {
		return CheckSum;
	}
	public void setCheckSum(String checkSum) {
		CheckSum = checkSum;
	}
	public String getLatitudeType() {
		return LatitudeType;
	}
	public void setLatitudeType(String latitudeType) {
		LatitudeType = latitudeType;
	}
	public String getLongitudeType() {
		return LongitudeType;
	}
	public void setLongitudeType(String longitudeType) {
		LongitudeType = longitudeType;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Time: " + this.time + "\n");
		sb.append("Latitude: " + this.Latitude + " (" + this.LatitudeType + ")" + "\n");
		sb.append("Longitude: " + this.Longitude + " (" + this.LongitudeType + ")" + "\n");
		sb.append("GPS quality: ");
		if(Quality == 0) sb.append(" invalid" + "\n");
		if(Quality == 1) sb.append(" GPS Fix" + "\n");
		if(Quality == 2) sb.append(" Diff. GPS Fix" + "\n");
		sb.append("Number of Sattelites: " + this.numberOfSattelites + "\n");
		sb.append("Horizontal dilution : " + this.HorizontalDilution + "\n");
		sb.append("Antenna altitude: " + this.AntennaAltitude + " " + this.AntennaUnits + "\n");
		sb.append("Geoidal separation: " + this.GeoidalSeparation + " " + this.GeoidalUnits + "\n");
		sb.append("Last Update: " + this.LastUpdate + "\n");
		sb.append("CheckSum: " + this.CheckSum + "\n");
		
		return sb.toString();
	}
}
